window.onload=function (){
	let userName = localStorage.getItem("currentLoginUser.aomall.com");
	if(userName!==null&&userName!=="")
	{
		document.getElementsByClassName("user")[0].children[0].href="javascript:void(0);";
		document.getElementsByClassName("user")[0].children[2].href="javascript:unLoad();";
		document.getElementsByClassName("user")[0].children[0].innerText = "欢迎您 "+userName+" !";
		document.getElementsByClassName("user")[0].children[2].innerText = "注销";
		console.log(1);
	}
	else
	{
		document.getElementsByClassName("user")[0].children[0].href="login.html";
		document.getElementsByClassName("user")[0].children[2].href="register.html";
		document.getElementsByClassName("user")[0].children[0].innerText = "登录";
		document.getElementsByClassName("user")[0].children[2].innerText = "免费注册";
		console.log(0);
	}
}

layui.use('layer', function () {
	var layer = layui.layer;
});

function unLoad(){
	localStorage.clear();
	window.location.href = "login.html";
}

$('.fixRecruiting button').click(function(event) {
	$(this).parent('.fixRecruiting').css('display', 'none');
});
$(function () {
	$(".SearchBtton").bind("click", function () {
		try {
			var value = $('.SearchBttonValue').val();
			var key = value.replace(/</g, "").replace(/>/g, "");
			goSearch($(this));

		}
		catch (e) {

		}
	});
});
var solr_pecialchar_and = "specialchar_insteadof_andchar";
function goSearch($this) {
	var key = $(".SearchBttonValue").val();
	var url = $(this).data("url");
	var lastChar = url.substr(url.length - 1); // => "1"
	if (lastChar == '/') {
		url = url.substr(0, url.length - 1);
	}

	if (key) {
		key = key.replace("&", solr_pecialchar_and);
		window.location.href = url + "/Store/Search/?q=" + key + "&crossStore=true";
	} else {
		window.location.href = url + "/Store/Search/?crossStore=true";
	}
}
/**
 * 品牌馆移入效果
 * @param  element e
 * @return {left, right}
 * @author yangyunxin
 * @date 2016-3-16
 */
$(".aut_brand_list").on("mouseenter", "li", function (e) {
	var $this = $(this);
	var $item = $(this).find(".show_brand_des");
	console.log(moveForward($this, e))
	$item.css(moveForward($this, e)).stop(true, true).animate({"left":"0px", "top": "0px"});
});
$(".aut_brand_list").on("mouseleave", "li", function (e) {
	var $this = $(this);
	var $item = $(this).find(".show_brand_des");
	$item.stop(true, true).animate(moveForward($this, e));
});
var moveForward = function(elem, e){
	var w = elem.width(), h = elem.height(), direction=0, cssprop={};
	var x = (e.pageX - elem.offset().left - (w / 2)) * (w > h ? (h / w) : 1);
	var y = (e.pageY - elem.offset().top - (h / 2)) * (h > w ? (w / h) : 1);

	direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
	switch(direction)
	{
		case 0://from top
			cssprop.left = 0;
			cssprop.top = "-100%";
			break;
		case 1://from right
			cssprop.left = "100%";
			cssprop.top = 0;
			break;
		case 2://from bottom
			cssprop.left = 0;
			cssprop.top = "100%";
			break;
		case 3://from left
			cssprop.left = "-100%";
			cssprop.top = 0;
			break;
	}
	return cssprop;
}

$(function() {
	// 固定部分的搜索
	var WBannerH=$('.star_brand').offset().top;
	var winHeight=$(window).height();
	$(window).scroll(function(event) {
		var WinH=$(window).scrollTop();
		if (WinH>WBannerH) {
			$('.fixSearch').fadeIn(0);
		} else{
			$('.fixSearch').fadeOut(0);
		};
	});
	// 固定部分的搜索
	var winHeight=$(window).height();
	$('.fixNav').height(winHeight);
	// 固定部分的导航
	$('.FC').hover(function() {
		$(this).children('.FLhover').stop().fadeIn(0);
	}, function() {
		$(this).children('.FLhover').stop().fadeOut(0);
	});
	$('.fixNav .top').click(function(){
		$('html,body').animate({scrollTop: 0}, 500);
	});
});